package pool.preprocess;

import java.util.Hashtable;
import java.util.Vector;

import pool.tablename.Pool;
import utility.Input;

import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;


public class Getproperty implements Process
{
	Pool pool;
	DBManager database;
	RecordSearch sr;
	String GETPROPERTY="getproperty";
	String RETURN= "return";
	GetIdName gid;
	
	
	public Hashtable<Object, Object> gethashtable() 
	{
		return null;
	}

	
	public void process(String value) 
	{
		if(pool.getRequestParameter().getProcess().equalsIgnoreCase("add"))
		{
			try 
			{
				sr =new RecordSearch(database);
				Hashtable<Object, Object> table = new Hashtable<Object, Object>();
				table.put("mid", value);
				table.put("pid",RETURN );
				sr.setConditionMap(table);
				String line[] = sr.getArrayFromResultSet();
				String Returnproperty="",Returnvalue="";
				for(int i=0;i<line.length;i++)
				{
					String splitline[]=line[i].split("\t");
					Returnproperty = splitline[Column.pv_index-1];
					if(Returnproperty.equals("0") || Returnproperty.equals("no$"))
						Returnproperty = splitline[Column.vt_index-1];
				}
				table.clear();
				table = pool.getHashtabel();
				String propertyname = table.get(GETPROPERTY).toString();
				propertyname = gid.getId(propertyname);
				Hashtable< Object, Object> temptable =new Hashtable<Object, Object>();
				temptable.put("mid", propertyname);
				temptable.put("pid", Returnproperty);
				sr.setConditionMap(temptable);
				line = sr.getArrayFromResultSet();
				for(int i=0;i<line.length;i++)
				{
					String splitline [] = line[i].split("\t");
					Returnvalue = splitline[Column.pv_index-1];
					if(Returnvalue.equals("0") || Returnvalue.equals("no$"))
						Returnvalue = splitline[Column.vt_index-1];
					else
						Returnvalue = gid.getItem(Returnvalue);
				}
				table.put(gid.getItem(Returnproperty), Returnvalue);
				pool.setHashtable(table);
			} catch (Exception e) 
			{	
				e.printStackTrace();
			}
		}
	}

	public void setObject(Object object, DBManager database) 
	{
		pool = (Pool) object;
		this.database = database;
		gid = new  GetIdName(database);
		RETURN = gid.getId(RETURN);
	}


	public void setType(String type, String table) 
	{
		
	}


	public void beforeAdd(String value) 
	{
		process(value);
	}


	public void beforeDel(String value) 
	{
	
	}


	public void beforeMod(String value) 
	{
		
	}


	public void beforeView(String value) 
	{
		
	}



	public Hashtable<Object, Object> getMasterMap() {
		// TODO Auto-generated method stub
		return null;
	}



	public Vector<Object> getPropertyVector() {
		// TODO Auto-generated method stub
		return null;
	}



	public void setBasicMap(Hashtable<Object, Object> Mastermap) {
		// TODO Auto-generated method stub
		
	}



	public void setDBManager(DBManager database) {
		// TODO Auto-generated method stub
		
	}



	public void setMasterMap(Hashtable<Object, Object> Mastermap) {
		// TODO Auto-generated method stub
		
	}



	public void setPropertyvector(Vector<Object> PropertyVector) {
		// TODO Auto-generated method stub
		
	}	

	

}
